package com.sesum;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;

public class Desactivate extends Sesum {
	
	
	private static final int DESACTIVATE_FAILED = 1;
	private static final int DESACTIVATE_OK = 2;
	

	@Override
	protected Dialog onCreateDialog(int id) {

		switch (id) {

		case DESACTIVATE_FAILED:
			return new AlertDialog.Builder(this)

			.setTitle("Resultado")

			.setMessage("Ha ocurrido un error, inténtelo de nuevo mas tarde")

			.setNeutralButton("Aceptar",

			new DialogInterface.OnClickListener() {

				public void onClick(DialogInterface dialog,

				int which) {

				}

			}).create();
			
		case DESACTIVATE_OK:
			return new AlertDialog.Builder(this)

			.setTitle("Resultado")

			.setMessage("Desactivado correctamente")

			.setNeutralButton("Aceptar",

			new DialogInterface.OnClickListener() {

				public void onClick(DialogInterface dialog,

				int which) {

				}

			}).create();

		default:
			break;
		}
		return null;
	}

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.desactivate);
		// Get the EditText and Button References
		final EditText etCarRegistration = (EditText) findViewById(R.id.car_registration);
		Button btnDesactivate = (Button) findViewById(R.id.desactivate_button);
		Button btnCancel = (Button) findViewById(R.id.cancel_button);
		// lblResult = (TextView)findViewById(R.id.result);

		btnDesactivate.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				// Check Login
					boolean result = updateState(login,password,etCarRegistration.getText().toString(),ACTIVATE_STATE);
					if (result) {
						showDialog(DESACTIVATE_OK);
						Toast
						.makeText(getApplicationContext(),
								"Desactivado",
								Toast.LENGTH_LONG);
						Intent intent = new Intent(getApplicationContext(),
								Desactivate.class);
						startActivity(intent);
					} else {
						showDialog(DESACTIVATE_FAILED);
					}
				}
		});

		btnCancel.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View v) {
				finish();

			}
		});

	}

}
